package org.example.simplemanagementsystem.service.impl;

import org.example.simplemanagementsystem.mapper.EmpMapper;
import org.example.simplemanagementsystem.mapper.StudentMapper;
import org.example.simplemanagementsystem.pojo.JobOption;
import org.example.simplemanagementsystem.pojo.StudentOption;
import org.example.simplemanagementsystem.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;


    @Override
    public JobOption getEmpJobData() {
        List<Map<String,Object>> list = empMapper.countEmpJobData();
        List<Object> jobList = list.stream().map(dataMap -> dataMap.get("pos")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("total")).toList();
        return new JobOption(jobList, dataList);
    }

    @Override
    public List<Map> getEmpGenderData() {
        return empMapper.countEmpGenderData();
    }

    @Override
    public List<Map> getStudentDegreeData() {
        return studentMapper.getStudentDegreeData();
    }

    @Override
    public StudentOption getStudentCountData() {
        List<Map> clazzList = studentMapper.getStudentCountData();
        StudentOption studentOption = new StudentOption();

        studentOption.setClazzList(
                clazzList.stream().map(dataMap -> dataMap.get("name")).toList()
        );
        studentOption.setDataList(
                clazzList.stream().map(dataMap -> dataMap.get("value")).toList()
        );
        return studentOption;
    }

}
